package com.etc.service.impl;


import com.etc.dao.ShoppingcartDao;
import com.etc.entity.Shoppingcart;
import com.etc.service.ShoppingcartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingcartServiceImpl implements ShoppingcartService{

    @Autowired
    ShoppingcartDao shoppingcartDao;

    @Override
    public boolean add(Shoppingcart record) {
        int n = shoppingcartDao.insert(record);
        return n>0;
    }

    @Override
    public List<Shoppingcart> dofindByUserIdAndGoodsId(Long userId, Long goodsId) {
        return shoppingcartDao.findByUserIdAndGoodsId(userId, goodsId);
    }

    @Override
    public boolean updateCount(Shoppingcart updated, Long userId, Long goodsId) {
        int i = shoppingcartDao.updateByUserIdAndGoodsId(updated, userId, goodsId);
        return i>0;
    }

    @Override
    public List<Shoppingcart> doFindByUserId(Long userId) {
        return shoppingcartDao.findByUserId(userId);
    }

    @Override
    public boolean doupdatGoodsCount(int goodsCount, Long userId, Long goodsId) {
        int i = shoppingcartDao.updatGoodsCount(goodsCount, userId, goodsId);
        return i>0;
    }

    @Override
    public boolean doDelS(Long userId, Long goodsId) {
        int i = shoppingcartDao.deleteByUserIdAndGoodsId(userId, goodsId);
        return i>0;
    }

    @Override
    public boolean doDelA(Long userId) {
        int i = shoppingcartDao.deleteByUserId(userId);
        return i>0;
    }
}
